package a.a.empty;

import android.annotation.SuppressLint;
import android.os.Build;
import android.util.Log;
import android.webkit.WebView;

public class BangcleWebView {

	static String def_code = "javascript:void(0)";
	static String cur_code = null;
	
	static public void OnFinish(WebView viewobj) {
    	try {
    		if(viewobj == null) {
    			Log.e("dhy.WEB", "viewobj is null");
    			return;
    		}
    		String url = viewobj.getUrl();
    		if( url == null ) {
    			Log.e("dhy.WEB", "url is null");
    			return;
    		}
    		url = url.toLowerCase();
	    	Log.d("dhy.WEB", "load: " + url);
    		if(cur_code == null) {
    			cur_code = null;//TODO js代码
    			if(cur_code == null)
    				cur_code = def_code;
    		}
    		Log.d("RiskStub.WEB", "load code " + cur_code);
    		viewobj.loadUrl(cur_code);
    	}catch(Exception e){
    		//e.printStackTrace();
    	}
	}
	
	@SuppressLint({ "SetJavaScriptEnabled", "JavascriptInterface" })
	static public void addJS(WebView viewobj) {
		try {
			Log.d("dhy.WEB", "add js called");
			if( Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 ) {
				Log.d("dhy.WEB", "cant use addJavascriptInterface android ver =" + Build.VERSION.SDK_INT);
			} else {
				viewobj.getSettings().setJavaScriptEnabled(true);
				BangcleWebView webView = new BangcleWebView();
				viewobj.addJavascriptInterface(webView, "empty_js");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
